package com.daqsoft.data;

import com.alibaba.fastjson.JSONObject;
import com.daqsoft.dto.MessageTypeEnum;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 通知消息类
 *
 * @author 周麟东 on 10:05
 */
public class Message {
    /**
     * 发送人
     */
    private User sender;

    /**
     * 收件人
     */
    private User receiver;

    /**
     * 发起时间
     */
    private Date date;

    /**
     * 消息主体
     */
    private String message;

    /**
     * 点击消息后跳转的链接
     */
    private String url;

    public User getSender() {
        return sender;
    }

    public void setSender(User sender) {
        this.sender = sender;
    }

    public User getReceiver() {
        return receiver;
    }

    public void setReceiver(User receiver) {
        this.receiver = receiver;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Message() {
    }

    public Message(User sender, User receiver, String message, String url) {

        this.sender = sender;
        this.receiver = receiver;
        this.message = message;
        this.url = url;
        this.date = new Date();

    }
    public Message(User sender, User receiver, String message) {
        this.sender = sender;
        this.receiver = receiver;
        this.message = message;
        this.date = new Date();
    }


    public Map<String, Object> toMap() {
        Map<String, Object> map = new HashMap<>();
        if (sender != null) {
            map.put("senderId", sender.getId());
            map.put("senderName", sender.getRealName());
        }
        map.put("receiverId", receiver.getId());
        map.put("receiverName", receiver.getRealName());
        map.put("message", message);
        map.put("url", url);
        return map;
    }

    /**
     *          {
     *              userId:用户ID int
     *              type: 消息类型 : @see com.daqsoft.dto.MessageTypeEnum
     *              msg:消息内容 string 或者 jsonString
     *            }
     * @return
     */
    public JSONObject toJson(){
        JSONObject map = new JSONObject();
        map.put("type", MessageTypeEnum.NOTICE.name());
        map.put("msg",this.message);
        return map;
    }
}
